#include "StdAfx.h"
#include "ContactBook.h"


CContactBook::CContactBook(void)
:CBaseList("ContactBook")
{
	SetSubKeyName("ContactGroup");
	m_pXMLDoc=NULL;
}

CContactBook::~CContactBook(void)
{
}
CBaseElement* CContactBook::NewNode()
{
	return new CContactGroup();
}
void CContactBook::ParseXMLNode()
{
	if (m_pXMLDoc && !this->GetFIsParsed())
	{
		//XMLNode = FXMLDoc->FirstChildElement(KeyName.c_str());
		this->SetXMLNode(m_pXMLDoc->FirstChildElement(this->GetKeyName().c_str()));
		//ResourceList->XMLNode = XMLNode->FirstChildElement(ResourceList->KeyName.c_str());
		//m_pServiceHeadList->SetXMLNode(this->GetXMLNode()->FirstChildElement(m_pServiceHeadList->GetKeyName()));
		//m_pServiceHeadList->ParseXMLNode();
		CBaseList::ParseXMLNode();

		this->SetFIsParsed(true);
	}
}
BOOL CContactBook::LoadFromFile(const liveneo::tstring & csFileName)
{
	if (csFileName!="")
    {
        m_sFileName = csFileName;
        if (m_pXMLDoc)
        {
            delete m_pXMLDoc;
        }
        m_pXMLDoc = new TiXmlDocument(csFileName.c_str());
        this->SetFIsParsed(false);
        return m_pXMLDoc->LoadFile();
    }
    return false;
}
BOOL CContactBook::SaveToFile(const liveneo::tstring &csFileName)
{
	if(m_pXMLDoc)
	{
		return m_pXMLDoc->SaveFile(csFileName.c_str());
	}
	return false;
}
void CContactBook::CreateNewProject(const liveneo::tstring caption,const liveneo::tstring name)
{
	if (!m_pXMLDoc)
    {
        m_pXMLDoc = new TiXmlDocument();
        TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "GB2312","yes");
        m_pXMLDoc->LinkEndChild( decl );
        CreateXMLNode();
        m_pXMLDoc->LinkEndChild( m_pXMLNode );
		this->SetCaption(caption);
		this->SetName(name);
		
        //this->Caption = ACaption;
        //this->Memo = AMemo;
    }
}
void CContactBook::AddContactGroup(CContactGroup* obj)
{
	this->AddHead(obj);
}